//
// Created by win10 on 24-12-12.
//
#include <stdio.h>

int Search(int arr[], int n, int key);

int main() {
    int n, m;
    while (scanf("%d",&n) != EOF) {
        int a[n];
        for (int i = 0; i < n; i++) {
            scanf("%d", &a[i]);
        }
        scanf("%d", &m);
        int b[m];
        for (int i = 0; i < m; i++) {
            scanf("%d", &b[i]);
        }
        for (int i = 0; i < n; i++) {
            for (int j = 0; j < n - i - 1; j++) {
                if (a[j] > a[j + 1]) {
                    int temp = a[j];
                    a[j] = a[j + 1];
                    a[j + 1] = temp;
                }
            }
        }
        for (int i = 0; i < n - 1; i++) {
            printf("%d ", a[i]);
        }
        printf("%d\n", a[n - 1]);
        for (int i = 0; i < m - 1; i++) {
            printf("%d ",Search(a, n, b[i]));
        }
        printf("%d\n",Search(a, n, b[m - 1]));
    }
    return 0;
}

int Search(int arr[], int n, int key) {
    int low = 0, high = n - 1, mid;
    while (low <= high) {
        mid = (low + high) / 2;
        if (arr[mid] == key) {
            return mid + 1;
        } else if (arr[mid] > key) {
            high = mid - 1;
        } else {
            low = mid + 1;
        }
    }
    return 0;
}
